/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package dao;

import controller.FuncionarioController;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import model.FuncionarioLogadoMODEL;

/**
 *
 * @author Welisson
 */
public class LoginDAO extends GenericDAO{

    private static final String EXISTE = "SELECT * FROM funcionario WHERE fun_cpf = ? AND fun_senha = ?";
    
    public FuncionarioLogadoMODEL existe(String cpf, String senha) throws SQLException {
        FuncionarioLogadoMODEL funcionario = null;
        
        PreparedStatement ps = conn.prepareStatement(EXISTE);
        
        ps.setString(1, cpf);
        ps.setString(2, senha);
        
        ResultSet rs = ps.executeQuery();
        
        while(rs.next()){
            funcionario = new FuncionarioLogadoMODEL();
            funcionario.setId(rs.getInt("fun_id"));
            funcionario.setCep(rs.getInt("log_cep"));
            funcionario.setNome(rs.getString("fun_nome"));
            funcionario.setCpf(rs.getString("fun_cpf"));
            funcionario.setRg(rs.getString("fun_rg"));
            funcionario.setNasc(rs.getDate("fun_nasc"));
            funcionario.setSexo(rs.getString("fun_sexo"));
            funcionario.setSenha(rs.getString("fun_senha"));
            funcionario.setNum(rs.getInt("fun_num"));
            
            rs.close();
            ps.close();
            conn.close();
            
            return funcionario;
        }
        
        rs.close();
        ps.close();
        conn.close();
        return funcionario;
    }
    
}
